<template>
    <div>
        <el-breadcrumb separator="->" class="bread">
            <el-breadcrumb-item><a href="/">首页</a></el-breadcrumb-item>
            <el-breadcrumb-item>汇率管理</el-breadcrumb-item>
        </el-breadcrumb>
        <el-table
            :data="currencyData"
            border
            style="width:451px"
        >
            <el-table-column
                label="币种"
                prop="currency"
                width="150">
            </el-table-column>
            <el-table-column
                label="汇率"
                width="150">
                <template slot-scope="scope">
                    <el-input :value="scope.row.rate"></el-input>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                width="150">
                <template slot-scope="scope">
                    <el-button @click="changeItem" type="success" size="medium">提交</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
export default {
    data(){
        return {
            currencyData:[]
        }
    },
    mounted(){
        this.$http.post('http://'+this.IP+'/api/getExchange.php')
                .then(res=>{
                    console.log(res.data)
                   this.currencyData = res.data.data
                })
    },
    methods:{
        changeItem(e){
            let currency = e.target.parentNode.parentNode.parentNode.previousElementSibling.previousElementSibling.children[0].innerHTML;
            let rate = e.target.parentNode.parentNode.parentNode.previousElementSibling.firstElementChild.firstElementChild.firstElementChild.value;
            console.log(rate)

            let params = new URLSearchParams();
            params.append('currency', currency);
            params.append('rate', rate);

            this.$http.post('http://'+this.IP+'/api/changeRate.php',params)
                .then(res=>{
                    console.log(res.data)
                    this.$router.replace('/')
                })
        },
    }
}
</script>
<style lang="less" scoped>

</style>
